// tslint:disable:no-any prefer-method-signature
import { Observable, Subscription } from 'rxjs';

/** 状态 */
export type UploadFileStatus = 'error' | 'success' | 'done' | 'uploading' | 'removed';

/** 上传方式 */
export type UploadType = 'select' | 'drag';

/** 上传列表的内建样式 */
export type UploadListType = 'text' | 'picture' | 'picture-card';

/** 文件对象 */
export interface UploadFile {
  uid: string;
  size?: number;
  name: string;
  filename?: string;
  lastModified?: string;
  lastModifiedDate?: Date;
  url?: string;
  status?: UploadFileStatus;
  originFileObj?: File;
  percent?: number;
  thumbUrl?: string;
  response?: ApesSafeAny;
  error?: ApesSafeAny;
  linkProps?: { download: string };
  type?: string;

  [key: string]: ApesSafeAny;
}

export interface UploadChangeParam {
  file: UploadFile;
  fileList: UploadFile[];
  event?: { percent: number };
  /** 回调类型 */
  type?: string;
}

export interface ShowUploadListInterface {
  showRemoveIcon?: boolean;
  showPreviewIcon?: boolean;
  showDownloadIcon?: boolean;
}

export type UploadTransformFileType = string | Blob | File | Observable<string | Blob | File>;

export interface ZipButtonOptions {
  disabled?: boolean;
  accept?: string | string[];
  action?: string | ((file: UploadFile) => string | Observable<string>);
  directory?: boolean;
  openFileDialogOnClick?: boolean;
  beforeUpload?(file: UploadFile, fileList: UploadFile[]): boolean | Observable<ApesSafeAny>;
  customRequest?(item: ApesSafeAny): Subscription;
  data?: {} | ((file: UploadFile) => {} | Observable<{}>);
  headers?: {} | ((file: UploadFile) => {} | Observable<{}>);
  name?: string;
  multiple?: boolean;
  withCredentials?: boolean;
  filters?: UploadFilter[];
  transformFile?(file: UploadFile): UploadTransformFileType;
  onStart?(file: UploadFile): void;
  onProgress?(e: ApesSafeAny, file: UploadFile): void;
  onSuccess?(ret: ApesSafeAny, file: UploadFile, xhr: ApesSafeAny): void;
  onError?(err: ApesSafeAny, file: UploadFile): void;
}

export interface UploadFilter {
  name: string;
  fn(fileList: UploadFile[]): UploadFile[] | Observable<UploadFile[]>;
}

export interface UploadXHRArgs {
  action?: string;
  name?: string;
  headers?: IndexableObject;
  file: UploadFile;
  postFile: string | Blob | File | UploadFile;
  data?: IndexableObject;
  withCredentials?: boolean;
  onProgress?(e: ApesSafeAny, file: UploadFile): void;
  onSuccess?(ret: ApesSafeAny, file: UploadFile, xhr: ApesSafeAny): void;
  onError?(err: ApesSafeAny, file: UploadFile): void;
}

export interface IndexableObject {
  [key: string]: ApesSafeAny;
}

export type ApesSafeAny = any;
